<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>事件防抖</title>
</head>

<body>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <p>hello world</p>
  <script src="./node_modules/lodash/lodash.js"></script>
  <script>
    // document.onscroll = function () {
    //   console.log('hello')
    // }

    // 参数1：函数
    // 参数2：时间
    // 返回值：被节流的函数
    // document.onscroll = _.debounce(function () {
    //   console.log('hello')
    // }, 500)

    function debounce(fun, delay) {
      return function (arguments) {
        //获取函数的作用域和变量
        let that = this
        let args = arguments
        clearTimeout(fun.id) // 清除定时器
        fun.id = setTimeout(function () {
          fun.call(that, args)
        }, delay)
      }
    }

  </script>
</body>

</html>
